<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>救生艇</title>
</head>
<body>
  <script>
    function fn(people, limit) {
      let ans = 0;
      people.sort((a, b) => a - b);
      let light = 0, heavy = people.length - 1;
      while (light <= heavy) {
        if (people[light] + people[heavy] <= limit) {
          ++light
        }
        --heavy
        ++ans
      }
      return ans
    }
    console.log(fn([1, 2], 3))
  </script>
</body>
</html>